$(document).ready(function(){
	var limit;
	var baseurl = $('#baseurl').val();
	var uid = $('#uid').val();
	var msgtype = $('#msgtype').val();
	switch(msgtype){
		case 'photos':
				buttonText = 'Browse Photos';
				fileExt = '*.jpg;*.gif;*.png';
				fileDesc = 'Image Files';
				folder = 'photos';
				limit = 5;
				break;
		case 'videos':
				buttonText = 'Browse Videos';
				fileExt = '*.avi;*.flv;*.3gp;*.3g2;*.mov;*.mp4;*.mpeg;*.swf;*.vob;*.wmv';
				fileDesc = 'Video Files';
				folder = 'videos';
				limit = 5;
				break;
		default:
		case 'documents':
				buttonText = 'Browse Files';
				fileExt = '*.doc;*.docx;*.txt;*.zip;*.pdf;*.ppt;*.rtf;*.xls;*.odt';
				fileDesc = 'Text Files';
				folder = 'documents';
				limit = 10;
				break;
	}
	$('#file_upload').uploadify({
		  'uploader'    : baseurl+'assets/js/uploadify/uploadify.swf',
		  'script'      : baseurl+'messages/upload',
		//  'script'      : baseurl+'assets/js/uploadify/uploadify.php',
		  'cancelImg'   : baseurl+'assets/js/uploadify/cancel.png',
		  'folder'      : '/messages/'+folder,

		  'buttonText' : buttonText,
		  'removeCompleted' : true,
		  'multi'           : true,
		  'fileExt'     : fileExt,
		  'fileDesc'    : fileDesc,
		  'queueSizeLimit' : limit,
		  'auto' : false,
		  'onAllComplete'  : function(event, ID, fileObj, response, data) {
				if(saveCaptured()){
			  		$('.error-r').html("Your message is successfully sent.").fadeIn('slow',function(){
						window.location = baseurl+'messages/type/'+msgtype;
						//$("#add-messages-wrap").fadeOut('slow');
					});
				} else {

				}
		  }
	});
});